<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.BaseQueryUploadFileActionBean"%>
<%@page import="com.feib.stms.util.StmsUtil"%>
<%@page import="com.feib.stms.model.LabelValue"%>
<%@page import="com.feib.stms.model.UploadFile"%>

<%
// 欄位排序處理
BaseQueryUploadFileActionBean actionBean = (BaseQueryUploadFileActionBean) request.getAttribute("actionBean");
actionBean.setNavigator();
pageContext.setAttribute("actionBeanClassName", actionBean.getClass().getName());
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>明細查詢</title>
            
    <script type="text/javascript">
    <!-- 
    
    window.name = 'queryFileContent';
    
    
    $(document).ready(function() {

        //var dialogArgs = window.dialogArguments;
        //var parentWindowObj = dialogArgs.parentWindowObj;
        
    	
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">


		//欄位隱藏顯示
		$('#hideColumnsBtn').click(function() 
		{
			var hideQryResultColumns = "true" == $('#hidden\\.hideQryResultColumns').val();
			
			hideColumns(hideQryResultColumns);
		
			$('#hidden\\.hideQryResultColumns').val(!hideQryResultColumns);
		});
		
		$('#doExportExcelFileBtn').click(function() {
			$("#hidden\\.doExportExcelFileBtn").trigger('click');
			
		});
	
		$("[id^='a-sortHeader-']").live("click", function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryResult\\.sortCriterion').val(sortField);
			
			var clazz = $(this).attr('class');
			if (null == clazz || 0 == clazz.length)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryResult\\.sortDirection').val('2');
				
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			
			waitingDialog({});
			$("#hidden\\.doQueryWithSowModalDialogBtn").trigger('click');			
			return false; <%// 此行一定要有，不然ie6不會執行submit%>
			
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			waitingDialog({});
			$("#hidden\\.doQueryWithSowModalDialogBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryWithSowModalDialogBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryWithSowModalDialogBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryWithSowModalDialogBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					doQueryAction();
					$('#hidden\\.queryResult\\.pageNumber').val(value);
					waitingDialog({});
					$("#hidden\\.doQueryWithSowModalDialogBtn").trigger('click');
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
</c:if>
    	
		<c:if test="${not empty actionBean.message}">
		showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
		</c:if>
		
		<c:if test="${not empty actionBean.errorMessage}">
		showErrorMessageDialog('<c:out value="${actionBean.errorMessage }" escapeXml="false"/>');
		</c:if>
		
		<c:if test="${not actionBean.hideQryResultColumns}">
		hideColumns(true);
		</c:if>  
	});
	
	function hideColumns(isHide)
    {
    	$('#listForm #queryResultTable tr th.needHide').each(function(i){
				
				var colindex = $(this).parent().children().index($(this)); 				
				
				if (isHide){
					$('#listForm #queryResultTable thead th:nth-child('+(colindex+1)+')').hide(); //隱藏column
	 				$('#listForm #queryResultTable tbody td:nth-child('+(colindex+1)+')').hide(); //隱藏column
	 				if ($('#hideColumnsBtn'))
	 					$('#hideColumnsBtn').val('顯示所有欄位');
	 				
				}
				else{
					$('#listForm #queryResultTable thead th:nth-child('+(colindex+1)+')').show(); //顯示column
	 				$('#listForm #queryResultTable tbody td:nth-child('+(colindex+1)+')').show(); //顯示column
 					$('#hideColumnsBtn').val('隱藏所有欄位');
				}
         });
    }
    
    function doPrintEvent()
    {
    	divPrint('listForm');
    	return false;
    }
    //-->
    </script>
</head>
<body>

	<div id="smallQueryForm"></div>

	<div id="queryForm"></div>
	

	<div id="listForm">
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">

			<div id="paginationBar" style=" margin: 0 auto;">
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4" /> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />&nbsp;
			</div>
                
                <table id="queryResultTable">
				<thead>
					<tr>
						<th>序號</th>
						<th><a id='a-sortHeader-accountNo' href='javascript:void(0);' class="<c:out value='${accountNoSortedClass }'/>"> <c:out value='${accountNoSortedSpan }' escapeXml="false"/>帳號</a> </th>						
						<th><a id='a-sortHeader-customerName' href='javascript:void(0);' class="<c:out value='${customerNameSortedClass }'/>"><c:out value='${customerNameSortedSpan }' escapeXml="false"/>客戶戶名 </a></th>
                        <th <%if (UploadFile.UPLOAD_FILE_PURCHASE_RETURN_PAYMENT.equals(actionBean.getUploadFileFormat())) out.print("class=\"needHide\"") ; %> ><a id='a-sortHeader-netIncome' href='javascript:void(0);' class="<c:out value='${netIncomeSortedClass }'/>"><c:out value='${netIncomeSortedSpan }' escapeXml="false"/>淨收金額 </a></th>
                        <th <%if (UploadFile.UPLOAD_FILE_PURCHASE_PAYMENT.equals(actionBean.getUploadFileFormat())) out.print("class=\"needHide\"") ; %>><a id='a-sortHeader-netPay' href='javascript:void(0);' class="<c:out value='${netPaySortedClass }'/>"> <c:out value='${netPaySortedSpan }' escapeXml="false"/>淨付金額</a></th>
                        <th class="needHide"><a id='a-sortHeader-accountNoChk' href='javascript:void(0);' class="<c:out value='${accountNoChkSortedClass }'/>"><c:out value='${accountNoChkSortedSpan }' escapeXml="false"/>帳號檢查碼M</a></th>
                        <th class="needHide"><a id='a-sortHeader-amountChk' href='javascript:void(0);' class="<c:out value='${amountChkSortedClass }'/>"><c:out value='${amountChkSortedSpan }' escapeXml="false"/>金額檢查碼N</a></th>
                        <th class="needHide"><a id='a-sortHeader-dealType' href='javascript:void(0);' class="<c:out value='${dealTypeSortedClass }'/>"><c:out value='${dealTypeSortedSpan }' escapeXml="false"/>處理類別 </a></th>
                        <th class="needHide"><a id='a-sortHeader-stockNo' href='javascript:void(0);' class="<c:out value='${fstockNoSortedClass }'/>"> <c:out value='${stockNoSortedSpan }' escapeXml="false"/>證券代號</a></th>
                        <th class="needHide"><a id='a-sortHeader-stockName' href='javascript:void(0);' class="<c:out value='${stockNameSortedClass }'/>"> <c:out value='${stockNameSortedSpan }' escapeXml="false"/>證券名稱</a></th>
                        <th class="needHide"><a id='a-sortHeader-chargebackPriority' href='javascript:void(0);' class="<c:out value='${chargebackPrioritySortedClass }'/>"> <c:out value='${chargebackPrioritySortedSpan }' escapeXml="false"/>扣款優先種類</a></th>
                        <th class="needHide"><a id='a-sortHeader-chargebackPriorityCode' href='javascript:void(0);' class="<c:out value='${chargebackPriorityCodeSortedClass }'/>"> <c:out value='${chargebackPriorityCodeSortedSpan }' escapeXml="false"/>扣款先後序號</a></th>
                        <th><a id='a-sortHeader-deliveryDate' href='javascript:void(0);' class="<c:out value='${deliveryDateSortedClass }'/>"><c:out value='${deliveryDateSortedSpan }' escapeXml="false"/>交割日期 </a></th>
                        <th><a id='a-sortHeader-teller' href='javascript:void(0);' class="<c:out value='${tellerSortedClass }'/>"> <c:out value='${tellerSortedSpan }' escapeXml="false"/>營業員</a></th>
                        <th><a id='a-sortHeader-dealResultCode' href='javascript:void(0);' class="<c:out value='${dealResultCodeSortedClass }'/>"><c:out value='${dealResultCodeSortedSpan }' escapeXml="false"/>狀態</a></th>
                        <th class="needHide"><a id='a-sortHeader-customerId' href='javascript:void(0);' class="<c:out value='${customerIdSortedClass }'/>"><c:out value='${customerIdSortedSpan }' escapeXml="false"/>身分證號</a></th>
                    </tr>
				</thead>
				<tbody>
                    <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
                    <tr>
                        <td align="right"><c:out value='${ rowstat.index + 1}'/></td>
                        <td><c:out value="${viewObj.accountNo }" /></td>
                        <td><c:out value="${viewObj.customerName }" /></td>
                        <td align="right"><fmt:formatNumber value="${viewObj.netIncome}" pattern="##,###" /></td>
                        <td align="right"><fmt:formatNumber value="${viewObj.netPay}" pattern="##,###" /></td>
                        <td><c:out value="${viewObj.accountNoChk }" /></td>
                        <td><c:out value="${viewObj.amountChk }" /></td>
                        <td><c:out value="${viewObj.dealType }" /></td>
                        <td><c:out value="${viewObj.stockNo }" /></td>
                        <td><c:out value="${viewObj.stockName }" /></td>
                        <td><c:out value="${viewObj.chargebackPriority }" /></td>
                        <td><c:out value="${viewObj.chargebackPriorityCode }" /></td>
                        <td align="center"><fmt:formatDate value="${viewObj.deliveryDate}" pattern="yyyy/MM/dd" /></td>
                        <td><c:out value="${viewObj.teller }" /></td>
                        <td><c:out value="${viewObj.dealResultCodeName }" /></td>
                        <td><c:out value="${viewObj.formatedCustomerId }" /></td>
                    </tr>
                    </c:forEach>
                    <c:if test="${null != actionBean.queryResult.totalObject }">
                     <tr>
                        <td align="right">總計</td>
                        <td colspan="15">
                        	淨收筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.netIncomeCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.netIncomeCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨收金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.netIncome }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.netIncome}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       		淨付筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.netPayCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.netPayCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨付金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.netPay }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.netPay}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       		淨收付筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.recordCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.recordCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨收付金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject.netIncomePayDiff }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject.netIncomePayDiff}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                       	
                        </td>
                    </tr>
                    </c:if>
                     <c:if test="${null != actionBean.queryResult.totalObject2 }">
                    <tr>
                        <td align="right">彙總</td>
                        <td colspan="15">
                        	淨收筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject2.netIncomeCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject2.netIncomeCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨收金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject2.netIncome }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject2.netIncome}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨付筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject2.netPayCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject2.netPayCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨付金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject2.netPay }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject2.netPay}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨收付筆數:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject2.recordCount }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject2.recordCount}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	淨收付金額:&nbsp;<c:choose><c:when test="${null != actionBean.queryResult.totalObject2.netIncomePayDiff }"><strong><fmt:formatNumber value="${actionBean.queryResult.totalObject2.netIncomePayDiff}" pattern="##,###" /></strong></c:when><c:otherwise>0</c:otherwise></c:choose>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  		 </td>
                    </tr>
                    </c:if>
				</tbody>
				<tfoot>
					<tr>
						<td colspan="16" class="listFunction">
							<input type="button" id="hideColumnsBtn" class="formBtn" value="隱藏所有欄位" />
							<input type="button" value="列印" onclick="javascript:doPrintEvent();" class="formBtn"/>
						</td>
					</tr>
				</tfoot>
                </table>
</c:if>
	</div>

<div style="display: none;">
<stripes:form id="hidden.queryUploadFileContentForm" beanclass="<%=actionBean.getClass().getName() %>" method="post" target="queryFileContent">
	<stripes:hidden id="hidden.qryPymentFileContent.group.groupPk" name="qryPymentFileContent.group.groupPk" />
	<stripes:hidden id="hidden.qryPymentFileContent.group.groupNo" name="qryPymentFileContent.group.groupNo" />
	<stripes:hidden id="hidden.qryPymentFileContent.uploadFile.uploadFilePk" name="qryPymentFileContent.uploadFile.uploadFilePk" />
	
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:hidden id="hidden.hideQryResultColumns" name="hideQryResultColumns" />
	
	
        
	<input type="hidden" id="decorator" name="decorator"  value="showModalDialogTemplate"/>
	<input type="hidden" id="confirm" name="confirm"  value="true"/>
	
	
	<stripes:submit id="hidden.doQueryWithSowModalDialogBtn" name="doQueryWithSowModalDialog" value="查詢" class="formBtn"/>
	<stripes:submit id="hidden.doExportExcelFileBtn" name="doExportExcelFile" value="明細表(Excel)" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>



</body>
</html>
